import mitt from 'mitt'

export interface EventBus {
  openMenu: [(open: boolean) => void] // 打开菜单
  closeMenu:[(close: boolean) => void] // 关闭菜单
  showMobileMenu: [(show: boolean) => void] // 是否展示菜单
}

const emitter = mitt<EventBus>()

export const addEmitEvent = (evtName: keyof EventBus, callback: (payload: any) => void) => emitter.on(evtName, callback)
export const emitEvent = (evtName: keyof EventBus, payload?: any) => emitter.emit(evtName, payload)
export const offEvent = (evtName: keyof EventBus, handler?: any) => emitter.off(evtName, handler || undefined)
export const offEvents = (list: Array<keyof EventBus>) => list.forEach(offEvent)
export const allEvent = emitter.all
export const clearEvent = () => emitter.all.clear()
export default emitter
